package com.weixin.pay.business;

import com.weixin.pay.WeiXinPayConfigure;
import com.weixin.pay.WeiXinPayUrl;
import com.weixin.pay.WeiXinResult;
import com.weixin.pay.domain.prepay.PrePayReqData;
import com.weixin.pay.domain.prepay.PrePayResData;
import com.weixin.pay.http.HttpClientHolder;
import com.weixin.pay.http.HttpSend;
import com.weixin.pay.util.XmlUtil;

/**
 * 预支付业务
 */
public class PrePayBusiness extends BaseBusiness {

    public PrePayBusiness(HttpClientHolder httpClientHolder, WeiXinPayConfigure weiXinPayConfigure) {
        super(httpClientHolder, weiXinPayConfigure);
    }

    public WeiXinResult<PrePayResData> prePay(PrePayReqData prePayReqData) {
        initCommonData(prePayReqData);
        String result = HttpSend.sendRequest(WeiXinPayUrl.PRE_PAY_API, prePayReqData, httpClientHolder);
        PrePayResData prePayResData = XmlUtil.getObjectFromXML(result, PrePayResData.class);
        return dealResult(prePayResData, result);
    }

}
